package com.zdsoft.blp.zongbuju.wode.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.zdsoft.blp.R;
import com.zdsoft.blp.zongbuju.wode.activity.WDXuanZeSheQu;

/**
 * Created by Administrator on 2016/9/2.
 */
public class SheQuxzAdapter extends BaseAdapter {
    private Context context;
    private LayoutInflater inflater;

    private int index =9999;

    public SheQuxzAdapter( Context context) {
        this.context = context;
        inflater = LayoutInflater.from(context);
    }


    public void change(int positon) {
        if (positon != index) {
            index = positon;
            notifyDataSetChanged();
        }
    }

    @Override
    public int getCount() {
        return WDXuanZeSheQu.lists.size();
    }

    @Override
    public Object getItem(int position) {
        return WDXuanZeSheQu.lists.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHodler hodler = null;

        if (convertView == null) {
            convertView = inflater.inflate(R.layout.wode_xuanzeshequ_item, null);

            hodler = new ViewHodler();

            hodler.iv_image = (ImageView) convertView.findViewById(R.id.iv_image);
            hodler.tv_title = (TextView) convertView.findViewById(R.id.tv_title);

            convertView.setTag(hodler);
        } else {
            hodler = (ViewHodler) convertView.getTag();
        }
        hodler.tv_title.setText(WDXuanZeSheQu.lists.get(position).getName());


        if (index == position|| WDXuanZeSheQu.lists.get(position).getXuanZhong()) {
            hodler.iv_image.setImageResource(R.drawable.fzg);
            WDXuanZeSheQu.lists.get(position).setXuanZhong(true);
        } else {
            hodler.iv_image.setImageResource(R.drawable.fzf);
        }
        return convertView;
    }

    class ViewHodler {
        ImageView iv_image;
        TextView tv_title;
    }

}
